const app=getApp()
 Page({

    /**
     * 页面的初始数据
     */
    data: {
      
    },
    onShow(){
      console.log(app.globalData.userInfo)
      this.setData({
        user:app.globalData.userInfo
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.getBanners(),
      this.getOrder()
      this.getGoodsList()
    },
  
    // 获取轮播图数据库记录
    getBanners(){
      wx.cloud.database().collection('shop_banners').get()
      .then(res=>{
        console.log(res)
        this.setData({
          bannerList:res.data
        })
      })
    },
    getOrder(){
      wx.cloud.database().collection('shop_order').get()
      .then(res=>{
        console.log(res)
        this.setData({
          selforder:res.data
        })
      })
    },
    getGoodsList(){
       wx.cloud.database().collection('shop_goods').get()
      // .where({
      //   status:true,
      //   isHome:true,
      //   stockNumber:wx.cloud.database().command.gt(0) //库存数量必须大于0
      // })
      //.get()
      .then(res=>{
        console.log(res)
        this.setData({
          goodsList:res.data
        })
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    toBannerDetail(event){
      console.log(event.currentTarget.dataset.id)
      let id = event.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/index/bannerDetail/bannerDetail?id='+id,
      })
    },
    toselforder(event){
      console.log(event.currentTarget.dataset.id)
      let id = event.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/order1/order1?id='+id,
      })
    },
    toGoodDetail(event){
      console.log(event.currentTarget.dataset.id)
        let id = event.currentTarget.dataset.id
        wx.navigateTo({
          url: '/pages/goodDetail/goodDetail?id='+id,
    })
    },
    toORcode(){
      wx.navigateTo({
        url: '/pages/index/ORcode/ORcode',
      })
    },

    //分享给好友 
onShareAppMessage(){
  return{
    title:this.data.good.title,
    path:'/pages/goodDetail/goodDetail='+this.data.good._id,
    imageUrl:this.data.good.cover
  }
},
//分享到朋友圈
onShareTimeline(){
  return {
    title:this.data.good.title,
    query:{
      id:this.data.good._id
  },
  imageUrl:this.data.good.cover
}
},
    
  })
    